package com.aaa.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/6/20 9:46
 * @description：我自己的监听器
 * @modified By：
 * @version: 1.0
 */
//@WebListener
public class MyListener  implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("servlet容器初始化啦");
        //此处要做大事，初始化spring的容器
        //初始化spring容器
        ApplicationContext ac=  new ClassPathXmlApplicationContext("applicationContext.xml");
        ServletContext servletContext = sce.getServletContext();
        servletContext.setAttribute("applicationContext",ac);
    }
}
